{% if submission.contest_or_none %}
    {% set prefix_length = submission.contest_or_none.problem.output_prefix_override %}
{% else %}
    {% set prefix_length = None %}
{% endif %}
{% set is_pretest = submission.is_pretested %}

{% if submission.status != 'IE' %}
    {% if submission.status == 'QU' %}
        <h4>{{ _('We are waiting for a suitable judge to process your submission...') }}</h4>
    {% elif submission.status == 'P' %}
        <h4>{{ _('Your submission is being processed...') }}</h4>
    {% elif submission.status == 'CE' %}
        <h3>{{ _('Compilation Error') }}</h3>
        <pre>{{ submission.error|ansi2html }}</pre>
    {% else %}
        {% if submission.error %}
            <h3>{{ _('Compilation Warnings') }}</h3>
            <pre>{{ submission.error|ansi2html }}</pre>
            <hr class="half-hr"><br>
        {% endif %}
        {% if is_pretest %}
            <h3>{{ _('Pretest Execution Results') }}</h3>
        {% else %}
            <h3>{{ _('Execution Results') }}</h3>
        {% endif %}
        <br>
        {% if statuses or not submission.is_graded %}
            {% for case in statuses %}
                {% if case.status == "AC" %}
                    <span class="fa fa-check case-AC"></span>
                {% elif case.status == "SC" %}
                    <span class="case-SC">&ndash;</span>
                {% else %}
                    <a href="#{{ case.id }}">
                        <span class="fa fa-times case-{{ case.status }} case-bad"></span>
                    </a>
                {% endif %}
                {% if case.num_combined > 1 %}
                    <sup class="case-{{ case.status }}">&times;{{ case.num_combined }}</sup>
                {% endif %}
            {% endfor %}
            {% if not submission.is_graded %}
                <span class="fa fa-spinner fa-pulse"></span>
            {% endif %}
            <br><br>
        {% endif %}
        {% set test_case_id = counter() %}
        {% for batch in batches %}
            {% if batch.id %}
                <b>{{ _('Batch #%(id)d', id=test_case_id()) }}</b>
                ({{ _('%(points)s/%(total)s points', points=batch.points|floatformat(0), total=batch.total|floatformat(0)) }})
                <br>
                <div class="batch-cases">
            {% endif %}
        <table class="submissions-status-table">{% for case in batch.cases %}
            {% set print_case_output = case.status != 'AC' and case.output and (prefix_length is none or prefix_length > 0) %}
            <tr id="{{ case.id }}" class="case-row toggle closed">
                <td>
                    {%- if print_case_output or case.extended_feedback -%}
                        <i class="fa fa-chevron-right fa-fw"></i>
                    {%- endif -%}
                    {%- if batch.id -%}
                        <b>{{ _('Case #%(id)d:', id=loop.index) }}</b>
                    {%- elif is_pretest -%}
                        <b>{{ _('Pretest #%(id)d:', id=test_case_id()) }}</b>
                    {%- else -%}
                        <b>{{ _('Test case #%(id)d:', id=test_case_id()) }}</b>
                    {%- endif -%}
                </td>

                <td>
                    <span title="{{ case.long_status }}" class="case-{{ case.result_class }}">
                        {%- if case.status == 'SC' %}&mdash;{% else %}{{ case.status }}{% endif -%}
                    </span>
                    {%- if case.feedback %}&nbsp;({{ case.feedback }}){% endif -%}
                </td>

                <td>
                    {%- if case.status != 'SC' -%}
                        {%- if case.status == 'TLE' -%}
                            [&gt;<span>{{ time_limit|floatformat(3) }}s,</span>
                        {%- else -%}
                            [<span title="{{ case.time }}s">{{ case.time|floatformat(3) }}s,</span>
                        {%- endif -%}
                    {%- endif -%}
                </td>

                <td>{% if case.status != 'SC' %}{{ case.memory|kbdetailformat }}]{% endif %}</td>

                {% if not batch.id %}
                    <td>({{ case.points|floatformat(0) }}/{{ case.total|floatformat(0) }})</td>
                {% endif %}
            </tr>

            {% if print_case_output or case.extended_feedback %}
                <tr id="{{ case.id }}-output" style="display:none" class="case-feedback toggled">
                    {% if print_case_output %}
                        <td colspan="5" class="case-output">
                            <div class="case-info">
                                <strong>{{ _('Your output (clipped)') }}</strong>
                                {% if prefix_length is none %}
                                    <pre class="case-output">{{ case.output|linebreaksbr }}</pre>
                                {% else %}
                                    <pre class="case-output">{{ case.output[:prefix_length]|linebreaksbr }}</pre>
                                {% endif %}
                            </div>
                        </td>
                    {% endif %}
                    {% if case.extended_feedback %}
                        <td colspan="5" class="case-ext-feedback">
                            <div class="case-info">
                                <strong>{{ _('Judge feedback') }}</strong>
                                <pre class="case-output">{{ case.extended_feedback|linebreaksbr }}</pre>
                            </div>
                        </td>
                    {% endif %}
                </tr>
            {% endif %}
        {% endfor %}
        </table>

        {% if batch.id %}</div>{% endif %}
            <br>
        {% endfor %}
        {% if submission.is_graded %}
            <br>
            {% if submission.result != "AB" %}
                <b>{{ _('Resources:') }}</b>
                {% if submission.result == "TLE" %}
                    <span>---,</span>
                {% else %}
                    <span title="{{ submission.time }}s">{{ submission.time|floatformat(3) }}s,</span>
                {% endif %}
                {{ submission.memory|kbdetailformat }}
                <br>
                {% if submission.result == "AC" %}
                    <b>{{ _('Maximum single-case runtime:') }}</b>
                    <span title="{{ max_execution_time }}s">{{ max_execution_time|floatformat(3) }}s</span>
                    <br>
                {% endif %}
                {% if is_pretest %}
                    <b>{{ _('Final pretest score:') }}</b>
                {% else %}
                    <b>{{ _('Final score:') }}</b>
                {% endif %}
                {{ submission.case_points|floatformat(0) }}/{{ submission.case_total|floatformat(0) }}
                {% if request.in_contest and submission.contest_or_none %}
                    {% with contest=submission.contest_or_none %}
                        {% set points=contest.points|roundfloat(3) %}
                        {% set total=contest.problem.points|floatformat(-1) %}
                        ({{ _('%(points)s/%(total)s points', points=points, total=total) }})
                    {% endwith %}
                {% else %}
                    {% with points=submission.points|roundfloat(3), total=submission.problem.points|floatformat(-1) %}
                        ({{ _('%(points)s/%(total)s points', points=points, total=total) }})
                    {% endwith %}
                {% endif %}
                {% if is_pretest and submission.result == "AC" %}
                    <br>
                    <i>{{ _('Passing pretests does not guarantee a full score on system tests.') }}</i>
                {% endif %}
            {% else %}
                <b>{{ _('Submission aborted!') }}</b>
            {% endif %}
            <br>
        {% endif %}
    {% endif %}
{% else %}
    {% include "submission/internal-error-message.html" %}
{% endif %}
